//
//  http_user.m
//  XV
//
//  Created by apple on 2019/03/11.
//  Copyright © 2019 XV. All rights reserved.
//

#import "http_user.h"
#import "UserInfoModel.h"
#import "MJExtension.h"
#import "XSJTool.h"


@implementation http_user

//用户注册
+(void)simple_register:(NSString*)nick_name phone:(NSString*)phone verify_code:(NSString*)verify_code invite_code:(NSString*)invite_code success:(SuccessData)ReqSuccess failure:(ErrorData)ReqFailure
{
    HttpTool *http = [HttpTool sharedManager];
    NSMutableDictionary *parameters = [[NSMutableDictionary alloc]initWithCapacity:3];
    
    if ( !kStringIsEmpty(nick_name) )
    {
        [parameters setObject:nick_name forKey:@"nick_name"];
    }
    
    if ( !kStringIsEmpty(phone) )
    {
        [parameters setObject:phone forKey:@"phone"];
    }
    
    if ( !kStringIsEmpty(verify_code) )
    {
        [parameters setObject:verify_code forKey:@"verify_code"];
    }
    
    if ( !kStringIsEmpty(invite_code) )
    {
        [parameters setObject:invite_code forKey:@"invite_code"];
    }
    
    NSString* strUrl = [http getMainUrl];
    strUrl = [strUrl stringByAppendingPathComponent:@"user/social/simple_register"];
    [http PostRequest:strUrl Parameters:parameters isSign:NO success:ReqSuccess failure:ReqFailure];
}

//用户登录
+(void)login:(NSString*)username password:(NSString*)password success:(SuccessData)ReqSuccess failure:(ErrorData)ReqFailure
{
    HttpTool *http = [HttpTool sharedManager];
    NSMutableDictionary *parameters = [[NSMutableDictionary alloc]initWithCapacity:2];
    
    if ( !kStringIsEmpty(username) )
    {
        [parameters setObject:username forKey:@"phone"];
    }
    
    if ( !kStringIsEmpty(password) )
    {
        [parameters setObject:password forKey:@"code"];
    }
    
    NSString* strUrl = [http getMainUrl];
    strUrl = [strUrl stringByAppendingPathComponent:@"user/login_by_phone"];
    [http PostRequest:strUrl Parameters:parameters isSign:NO success:ReqSuccess failure:ReqFailure];
}


//验证码【register：注册；login：验证码登录】
+(void)sendCode:(NSString*)phone type:(NSString*)type success:(SuccessData)ReqSuccess failure:(ErrorData)ReqFailure
{
    HttpTool *http = [HttpTool sharedManager];
    NSMutableDictionary *parameters = [[NSMutableDictionary alloc]initWithCapacity:2];
    
    if ( !kStringIsEmpty(phone) )
    {
        [parameters setObject:phone forKey:@"phone"];
    }
    
    if ( !kStringIsEmpty(type) )
    {
        [parameters setObject:type forKey:@"type"];
    }
    
    NSString* strUrl = [http getMainUrl];
    strUrl = [strUrl stringByAppendingPathComponent:@"msg/phonemsg/verify_code"];
    [http PostRequest:strUrl Parameters:parameters isSign:NO success:ReqSuccess failure:ReqFailure];
}

//手机验证码登录send_code=》发送验证码 login=》校验验证码并登陆
+(void)full_register:(NSString*)mobile type:(NSString*)type code:(NSString*)code success:(SuccessData)ReqSuccess failure:(ErrorData)ReqFailure
{
    HttpTool *http = [HttpTool sharedManager];
    NSMutableDictionary *parameters = [[NSMutableDictionary alloc]initWithCapacity:2];
    
    if ( !kStringIsEmpty(mobile) )
    {
        [parameters setObject:mobile forKey:@"mobile"];
    }
    
    if ( !kStringIsEmpty(type) )
    {
        [parameters setObject:type forKey:@"type"];
    }
    
    if ( !kStringIsEmpty(code) )
    {
        [parameters setObject:code forKey:@"invite_code"];
    }
    
    NSString* strUrl = [http getMainUrl];
    strUrl = [strUrl stringByAppendingPathComponent:@"user/social/simple_register"];
    [http PostRequest:strUrl Parameters:parameters isSign:NO success:ReqSuccess failure:ReqFailure];
}

//退出
+(void)logout:(NSString*)user_id success:(SuccessData)ReqSuccess failure:(ErrorData)ReqFailure
{
    HttpTool *http = [HttpTool sharedManager];
    NSMutableDictionary *parameters = [[NSMutableDictionary alloc]initWithCapacity:2];
    
    if ( !kStringIsEmpty(user_id) )
    {
        [parameters setObject:user_id forKey:@"user_id"];
    }
    
    NSString* strUrl = [http getMainUrl];
    strUrl = [strUrl stringByAppendingPathComponent:@"user/logout"];
    [http PostRequest:strUrl Parameters:parameters isSign:NO success:ReqSuccess failure:ReqFailure];
}



@end
